package com.gisocn.onemap.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.gisocn.onemap.base.BaseActivity;
import com.gisocn.onemap.interfaces.OnItemClickListener;
import com.gisocn.onemap.model.AppConfig;
import com.gisocn.onemap.model.FileCenter;
import com.gisocn.onemap.model.ImageWall;
import com.gisocn.onemap.presenter.FilePackagePresenter;
import com.gisocn.onemap.sgzx.R;
import com.gisocn.onemap.ui.adapter.FilePackageAdapter;
import com.gisocn.onemap.view.FilePackageView;
import com.google.gson.Gson;
import com.tencent.smtt.sdk.TbsVideoCacheTask;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Iterator;

/* loaded from: classes2.dex */
public class OnlineFileActivity extends BaseActivity<FilePackagePresenter> implements FilePackageView {
    private AppConfig appConfig;
    FilePackageAdapter filePackageAdapter;
    @BindView(R.id.recycle_file)
    RecyclerView recycleFile;
    @BindView(R.id.tv_close)
    TextView tvClose;
    @BindView(R.id.tv_right)
    TextView tvRight;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    private ArrayList<FileCenter> fileCenterList = new ArrayList<>();
    Handler handler = new Handler() { // from class: com.gisocn.onemap.ui.activity.OnlineFileActivity.2
        @Override // android.os.Handler
        public void handleMessage(Message message) {
            super.handleMessage(message);
            if (message.what != 1) {
                return;
            }
            OnlineFileActivity.this.filePackageAdapter.notifyDataSetChanged();
        }
    };

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.gisocn.onemap.base.BaseActivity, androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, androidx.core.app.ComponentActivity, android.app.Activity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_online_file);
        ButterKnife.bind(this);
        initView();
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.gisocn.onemap.base.BaseActivity
    public FilePackagePresenter createPresenter() {
        return new FilePackagePresenter(this);
    }

    void initView() {
        AppConfig appConfig = (AppConfig) new Gson().fromJson(getIntent().getStringExtra("appConfig"), (Class<Object>) AppConfig.class);
        this.appConfig = appConfig;
        if (appConfig.getMediaData() != null) {
            ((FilePackagePresenter) this.presenter).getFileCenter(this.appConfig.getMediaData().getUrl().trim());
        }
        this.tvClose.setVisibility(8);
        this.tvRight.setText("关闭");
        this.tvTitle.setText("在线资料");
        int dimensionPixelOffset = getResources().getDimensionPixelOffset(R.dimen.dp_165);
        Log.e("item", "" + dimensionPixelOffset);
        this.recycleFile.setLayoutManager(new GridLayoutManager(this, (int) Math.floor((double) (getResources().getDisplayMetrics().widthPixels / dimensionPixelOffset))));
        FilePackageAdapter filePackageAdapter = new FilePackageAdapter(this.fileCenterList, this, 1);
        this.filePackageAdapter = filePackageAdapter;
        this.recycleFile.setAdapter(filePackageAdapter);
        this.filePackageAdapter.setOnItemClickListener(new OnItemClickListener() { // from class: com.gisocn.onemap.ui.activity.OnlineFileActivity.1
            @Override // com.gisocn.onemap.interfaces.OnItemClickListener
            public void onItemClick(View view, int i, int i2) {
            }

            @Override // com.gisocn.onemap.interfaces.OnItemClickListener
            public void onItemClick(View view, int i) {
                Log.e("链接", "" + ((FileCenter) OnlineFileActivity.this.fileCenterList.get(i)).getHerf());
                String str = MainActivity.MEDIADATA_PATH + ((FileCenter) OnlineFileActivity.this.fileCenterList.get(i)).getHerf();
                if (((FileCenter) OnlineFileActivity.this.fileCenterList.get(i)).getType() == 1) {
                    Log.e("链接", "" + ((FileCenter) OnlineFileActivity.this.fileCenterList.get(i)).getHerf());
                    ((FilePackagePresenter) OnlineFileActivity.this.presenter).getFileCenter(str);
                    return;
                }
                String substring = str.substring(str.lastIndexOf("/") + 1);
                if (OnlineFileActivity.this.isNull(substring)) {
                    OnlineFileActivity.this.showToast("无法获取文件");
                    return;
                }
                Intent intent = new Intent(OnlineFileActivity.this, FileBrowseActivity.class);
                intent.putExtra(TbsVideoCacheTask.KEY_VIDEO_CACHE_PARAM_URL, str);
                intent.putExtra("fileUrl", ((FileCenter) OnlineFileActivity.this.fileCenterList.get(i)).getHerf());
                intent.putExtra("fileName", substring);
                ArrayList arrayList = new ArrayList();
                Iterator it = OnlineFileActivity.this.fileCenterList.iterator();
                while (it.hasNext()) {
                    FileCenter fileCenter = (FileCenter) it.next();
                    String name = fileCenter.getName();
                    if (name.contains("png") || name.contains("PNG") || name.contains("jpg") || name.contains("JPG") || name.contains("gif") || name.contains("GIF") || name.contains("jpeg") || name.contains("JPEG")) {
                        try {
                            arrayList.add(new ImageWall(fileCenter.getName(), URLDecoder.decode(fileCenter.getHerf(), "utf-8"), i));
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }
                    }
                }
                intent.putExtra("imageWalls", arrayList);
                OnlineFileActivity.this.startActivity(intent);
            }
        });
    }

    @OnClick({R.id.tv_close, R.id.tv_right})
    public void onViewClicked(View view) {
        if (view.getId() != R.id.tv_right) {
            return;
        }
        finish();
    }

    @Override // com.gisocn.onemap.view.FilePackageView
    public void getFileCenter(ArrayList<FileCenter> arrayList) {
        Log.e("data.size()", "" + arrayList.size());
        this.fileCenterList.clear();
        this.fileCenterList.addAll(arrayList);
        this.handler.sendEmptyMessage(1);
    }
}
